﻿using Microsoft.AspNetCore.Http;
using System.Net;

namespace DotNetHackathon.GBA.ApiCommon.ExceptionHandling
{
    public class DefaultHttpExceptionStatusCodeFinder : IHttpExceptionStatusCodeFinder
    {
        public virtual HttpStatusCode GetStatusCode(HttpContext httpContext, Exception exception)
        {
            if (exception is IHasErrorCode exceptionWithErrorCode && !string.IsNullOrEmpty(exceptionWithErrorCode.Code))
            {
                return HttpStatusCode.BadRequest;
            }

            return HttpStatusCode.InternalServerError;
        }
    }
}
